{template header}
<style type="text/css">
    .btn_cancel{ display: inline-block; height: 30px; width: 60px; border: 1px solid #CE2932; line-height: 30px; border-radius: 5px; 
    text-align: center; margin-top: 5px; color: #CE2932; }
</style>
<body>
    <!-- S header -->
    <header>
        <a href="/index.php?m=user"  class="headerL iconfont">&#xe66a;</a>
        <h1>交易</h1>
    </header>
    <!-- E header -->
    <ul class="flex my_deal_tab_title">
        <li class="cur" data-type="1"><a href="javascript:;">买入</a></li>
        <li  data-type="2"><a href="javascript:;">卖出</a></li>
        <li  data-type="3"><a href="javascript:;">交易中</a></li>
        <li  data-type="4"><a href="javascript:;">完成</a></li>
    </ul>
    <ul id="listcon">
        
        
        <!-- <li class="my_deal_dbt_info">
            <div class="flex flex-pack-justify number">
                <div>编号&nbsp;4801096</div>
                <div class="red relative">等待付款</div>
            </div>
            <div class="flex pirce_list">
                <dl>
                    <dt>1.000</dt>
                    <dd>数量(DBT)</dd>
                </dl>
                <dl>
                    <dt>1.49$</dt>
                    <dd>单价</dd>
                </dl>
                <dl>
                    <dt>1.49$</dt>
                    <dd>总价</dd>
                </dl>
            </div>
            <div class="time flex flex-pack-justify">
                <div>时间&nbsp;2018-8-1 10:46:17</div>
                <div class="count_down">倒计时&nbsp;03:46:17</div>
            </div>
        </li> -->
    </ul>
</body>
<script type="text/html" id="list_model">
<% if(list.length >0){%>
    <% for (var k in list) { var v = list[k]; %>
    
        <li class="my_deal_dbt_info">
          <a href="/index.php?m=user&c=trade&a=tradedetail&id=<%=v.id%>">
            <div class="flex flex-pack-justify number">
                <div>编号&nbsp;<%=v.order_sn%></div>
                <div class="red relative"><%=v.status_txt%></div>
            </div>
            <div class="flex pirce_list">
                <dl>
                    <dt><%=v.num%></dt>
                    <dd>数量(DBT)</dd>
                </dl>
                <dl>
                    <dt><%=v.price%>$</dt>
                    <dd>单价</dd>
                </dl>
                <dl>
                    <dt><%=v.cny%>¥</dt>
                    <dd>总价</dd>
                </dl>
            </div>
            </a>
            <div class="time flex flex-pack-justify">
                <div>时间&nbsp;<%=v.addtime%></div>
                <div class="count_down" id="c_down_<%=v.id%>"></div>
                <% if(v.status==1 && v.type==2){ %>
                <a href="javascript:;" data-id="<%=v.id%>" onClick="tcancal(<%=v.id%>);"  class="btn_cancel">取消</a>
                <% } %>                
            </div>
        </li>
    
    <%
    if(v.status==2){
        fromatMoney(v.id,v.ctime)
    }
    %>
    <%}%>
    <li class="loading"><div class="spinner"><i></i></div>数据读取中</li>
<%  } %>
</script>
<script type="text/javascript" src="{THEME_PATH}js/template.js"></script>
<script type="text/javascript" src="{THEME_PATH}js/ncscroll-load.js"></script>
<script>
var type =1;
var pagesize = 10;
//渲染list
var load_class = new ncScrollLoad();
load_class.loadInit({'url':'/index.php?m=user&c=trade&a=tradelog_ajax','getparam':{'type':type},'tmplid':'list_model','containerobj':$("#listcon"),'iIntervalId':true});
    function tab(menus) {
        $(menus).click(function() {
            var index = $(this).index();
                $(this).addClass("cur").siblings().removeClass("cur");
                console.log($(this).data("type"));
                type = $(this).data("type");

                load_class.loadInit({
                  'url':'/index.php?m=user&c=trade&a=tradelog_ajax',
                  'getparam':{'type':type},
                  'tmplid':'list_model',
                  'containerobj':$("#listcon"),
                  'iIntervalId':true
                });
              // $(conts).eq(index).removeClass("hide").siblings().addClass("hide");
        })
    }
    tab(".my_deal_tab_title li");

template.helper("fromatMoney", function (id,ctime) {
    countDown(id,ctime);
});
//    template.registerModifier('up', function (str) {
//     return str.toUpperCase();
// });


function countDown(id,times){
  var timer=null;
  timer=setInterval(function(){
    var day=0,
      hour=0,
      minute=0,
      second=0;//时间默认值
    if(times > 0){
      // day = Math.floor(times / (60 * 60 * 24));
      hour = Math.floor(times / (60 * 60)) - (day * 24);
      minute = Math.floor(times / 60) - (day * 24 * 60) - (hour * 60);
      second = Math.floor(times) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
    }
    // if (day <= 9) day = '0' + day;
    if (hour <= 9) hour = '0' + hour;
    if (minute <= 9) minute = '0' + minute;
    if (second <= 9) second = '0' + second;
    $("#c_down_"+id).html("倒计时&nbsp;"+hour+":"+minute+":"+second);
    // console.log(hour+":"+minute+":"+second);
    times--;
  },1000);
  if(times<=0){
    clearInterval(timer);
  }
}



function tcancal(id){
    layer.open({
      content: '是取消该交易？'
      ,btn: ['是', '否']
      ,yes: function(index){
          $.ajax({
            type:'post',
            url:'/index.php?m=user&c=trade&a=cancel',
            data:{id:id},
            dataType:'json',
            success:function(ret){
              layer.closeAll();
              console.log(ret);
              if(ret.status==1){
                  tips(ret.info,'/index.php?m=user&c=trade&a=tradelog');
              }else{
                  hd_alert(ret.info);
              }
            }
          })
      }
    });
}
</script>
</html>